﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Environment;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Protocol.section;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Protocol.player;

namespace Pixysoft.Weblications.Sango.Command.section
{
    partial class SangoSectionHandler
    {
        public section_move section_move(double geox, double geoy)
        {
            string userCode = SangoManager.Authentication();

            section_move response = ReflectionManager.CreatePojo<section_move>();
            response.Succeed = false;

            Entities.Usr_Queue queue = UsrQueueDao.UsrQueueStartup(
                userCode, CtiQueueTypecodeCollection.DISTRICT_MOVE, userCode, SectionFormular.default_section_move_timespan);

            if (queue == null)
            {
                response.Message = "迁移冷却中";
                return response;
            }

            Entities.Usr_Section oldsection = UsrSectionDao.GetSection(userCode);
            Entities.Sys_Section sysSection = SysSectionHelper.trySearchSectionByGeolocation(geox, geoy);
            UsrSectionDao.moveSection(sysSection, oldsection, geox, geoy);

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;

            command.Begin(delegate()
            {
                command.Update(oldsection);

                command.Update(queue);

                command.Commit();
            });

            response.queue = UsrQueueFacade.ToQueue(queue);
            response.section = UsrSectionFacade.ToSection(oldsection);
            response.Succeed = true;
            return response;
        }
    }
    public interface section_move : ISangoResponse
    {
        player_queue queue { get;set;}

        player_section section { get;set;}
    }
}